package cn.fintecher.pangolin.service.dataimp.web;

import cn.fintecher.pangolin.common.model.UploadFile;
import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.service.dataimp.request.ExportUserRequest;
import cn.fintecher.pangolin.service.dataimp.service.UserExportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Auther: xiaqun
 * @Description: 用户导出相关接口
 * @Date: 14:14 2019/9/25
 */

@RestController
@RequestMapping("/api/userExportController")
@Api(value = "用户导出相关接口", description = "用户导出相关接口")
public class UserExportController extends BaseController {
    @Autowired
    private UserExportService userExportService;

    /**
     * 导出人员花名册
     */
    @ApiOperation(value = "导出人员花名册", notes = "导出人员花名册")
    @PostMapping("/exportUserList")
    public ResponseEntity<Void> exportUserList(@RequestBody ExportUserRequest request,
                                               @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to export user list,{}", request);
        userExportService.exportUserList(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 下载导入花名册模板
     */
    @ApiOperation(value = "下载导入花名册模板", notes = "下载导入花名册模板")
    @GetMapping("/downloadUserTemplate")
    public ResponseEntity<UploadFile> downloadUserTemplate() {
        log.info("REST request to download user template");
        UploadFile uploadFile = userExportService.downloadUserTemplate();
        return ResponseEntity.ok().body(uploadFile);
    }

    /**
     * 导入花名册
     */
    @ApiOperation(value = "导入花名册", notes = "导入花名册")
    @GetMapping("/uploadUser")
    public ResponseEntity<Void> uploadUser(@RequestParam @ApiParam(value = "文件ID", required = true) String fileId,
                                           @RequestHeader(value = "X-UserToken") String token) throws IOException {
        log.info("REST request to upload user,{}", fileId);
        userExportService.uploadUser(fileId, token);
        return ResponseEntity.ok().build();
    }
}
